/**
 * Program  : EvacuationMapAdapter.java
 * Author   : long
 * Create   : 2016年5月6日 上午10:39:58
 *
 * Copyright 2016 by Embedded Internet Solutions Inc.,
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Embedded Internet Solutions Inc.("Confidential Information").  
 * You shall not disclose such Confidential Information and shall 
 * use it only in accordance with the terms of the license agreement 
 * you entered into with Embedded Internet Solutions Inc.
 *
 */
	
package cn.broadin.app.hotel.adapter;

import java.util.List;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import cn.broadin.app.hotel.R;
import pl.droidsonroids.gif.GifImageView;

/**
 * 疏散图GridView适配器
 * 
 * @author   long
 * @version  1.0.0
 * @date 2016年5月6日上午10:39:58
 */
@SuppressLint("ViewHolder")
public class EvacuationMapAdapter extends BaseAdapter{
	
	private List<String> mapList;
	private Context mContext;
	private LayoutInflater mLayoutInflater;
	
	public EvacuationMapAdapter(List<String> mapList, Context context){
		this.mapList = mapList;
		this.mContext = context;
		this.mLayoutInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mapList.size();
	}
	
	@Override
	public Object getItem(int position) {
		return mapList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		HolderView mHolderView = null;
		if(convertView == null){
			convertView = mLayoutInflater.inflate(R.layout.evacuation_map_item, null);
			
			mHolderView = new HolderView();
			mHolderView.mImageView = (ImageView) convertView.findViewById(R.id.evacuation_map);
			
			convertView.setTag(mHolderView);
		} else {
			mHolderView = (HolderView) convertView.getTag();
		}
		
		String url = mapList.get(position);
		loadBitmap(mHolderView.mImageView, url);
		
		return convertView;
	}
	
	
	private class HolderView{
		public ImageView mImageView;
//		public GifImageView mImageView;
	}

	public List<String> getMapList() {
		return mapList;
	}

	public void setMapList(List<String> mapList) {
		this.mapList = mapList;
	}
	
	
	/**
	 * 加载bitmap图片
	 * 
	 * @author   long
	 * @param imageView
	 * @return void
	 * @exception
	 * @author   long
	 * @since 1.0.0
	 * @date 2015年9月23日 下午4:32:44
	 */
	public void loadBitmap(final ImageView imageView, String uri){
		BitmapUtils bitmapUtils = new BitmapUtils(mContext);
		BitmapDisplayConfig displayConfig = new BitmapDisplayConfig();
		bitmapUtils.configDefaultDisplayConfig(displayConfig);
		bitmapUtils.display(imageView, uri);
	}
}
